var $foodcategories = $('#foodcategories'),
	serverUrl	= 'http://localhost/zigo/server/home.php/';


FoodCate = Backbone.Model.extend({
	defaults: {
		category_place_id: '',
		category_place_name: ''
	},
	urlRoot: serverUrl + 'foodcategories'
});

FoodCateCollection = Backbone.Collection.extend({
	model: FoodCate,
	url: serverUrl + 'foodcategories'
});

FoodCateViewItem = Backbone.View.extend({
	tagName: 'li',
	className: 'list-group-item',
	initialize: function() {
		this.render = _.bind(this.render, this);
		this.template = _.template($('#foodcate-item').html());
		//this.model.bind('change', this.render);
	},
	render: function() {
		this.$el.html(this.template(this.model.attributes));
		return this;
	}
});
FoodCateList = Backbone.View.extend({
	initialize: function() {
		_(this).bindAll('add');

		this._foodcates = [];
		
		this.collection.each(this.add);
		
		this.collection.bind('add', this.add);
	},
	render: function() {
		this._rendered = true;
		this.$el.empty();
		_(this._foodcates).each(function(item) {
			$foodcategories.append(item.render().el);
		});
	},
	add: function(food) {
		var foodCateItem = new FoodCateViewItem({model: food});

		this._foodcates.push(foodCateItem);

		if (this._rendered) {
			this.$el.append(foodCateItem.render().el);
		}
	}
});

